<!-- 储存组织相关控件 -->
<template>
  <!-- 组织类型 -->
  <OrganizationType
    v-if="fieldName === 'organization_type'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </OrganizationType>
  <!-- 组织名称
  <OrganizationName
    v-if="code === 'ORGANIZATION_NAME'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </OrganizationName>

  <!== 组织简称 ==>
  <OrganizationAbbreviation
    v-if="code === 'ORGANIZATION_ABBREVIATION'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </OrganizationAbbreviation>

  <!== 组织编码 ==>
  <OrganizationCode
    v-if="code === 'ORGANIZATION_CODE'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </OrganizationCode>

  <!== 上级组织 ==>
  <OrganizationSuperior
    v-if="code === 'ORGANIZATION_SUPERIOR'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </OrganizationSuperior>

  <!== 组织负责人 ==>
  <OrganizationLeader
    v-if="code === 'ORGANIZATION_LEADER'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </OrganizationLeader>

  <!== 编制人数 ==>
  <OrganizationHeadcount
    v-if="code === 'ORGANIZATION_HEADCOUNT'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </OrganizationHeadcount>

  <!== 分管领导 ==>
  <OrganizationSecondLeader
    v-if="code === 'ORGANIZATION_SECOND_LEADER'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </OrganizationSecondLeader>

  <!== 工作地点 ==>
  <OrganizationAddress
    v-if="code === 'ORGANIZATION_ADDRESS'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </OrganizationAddress>

  <!== 是否为独立法人 ==>
  <OrganizationLegalPerson
    v-if="code === 'ORGANIZATION_LEGAL_PERSON'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </OrganizationLegalPerson>

  <!== 是否为虚拟组织 ==>
  <OrganizationVirtual
    v-if="code === 'ORGANIZATION_VIRTUAL'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  ></OrganizationVirtual>

  <!== 组织机构代码 ==>
  <OrganizationCodeCertificate
    v-if="code === 'ORGANIZATION_CODE_CERTIFICATE'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  ></OrganizationCodeCertificate>

  <!== 集团名称 ==>
  <GroupName
    v-if="code === 'GROUP_NAME'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  ></GroupName>

  <!== 集团简称 ==>
  <GroupAbbreviation
    v-if="code === 'GROUP_ABBREVIATION'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  ></GroupAbbreviation>

  <!== 集团简介 ==>
  <GroupProfile
    v-if="code === 'GROU_PPROFILE'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  ></GroupProfile> -->
</template>

<script setup lang="ts">
import OrganizationType from './OrganizationType.vue';
const props = withDefaults(
  //参数说明
  defineProps<{
    componentType?: string;
    code?: string;
    fieldName?: string;
    props: { [propName: string]: any };
    name?: string;
    required?: boolean;
    disabled?: boolean;
    values: any;
    regex?: {
      [name: string]: {
        role: any;
        name: any;
      };
    };
  }>(),
  {}
);

// console.log(props);

const emit = defineEmits(['update:values']);
//复制一份props
const getProps = computed(() => {
  return props.props;
});

const validator = (value: any, callback: any) => {
  const { componentType, name, values, required, regex } = props;
  if (componentType === 'TEXT') {
    //单行输入框
    const { validate } = getProps.value;
    if (required && !values[0]) return callback('请输入' + name);
    if (!validate) return callback();

    if (regex) {
      const roleItem = regex[validate];
      const checkVal = roleItem.role.test(values[0]);
      if (!checkVal) {
        return callback(new Error('请输入正确的' + roleItem.name));
      }
    }
  } else if (componentType === 'TEXT_AREA') {
    //多行输入框
    if (required && !values[0]) return callback(`请输入${name}`);
  } else if (componentType === 'NUMBER') {
    if (required && !values[0]) return callback(`请输入${name}`);
  } else if (componentType === 'DATE' || componentType === 'DATE_RANGE') {
    if (required && !values[0]) return callback(`请选择日期`);
  }

  callback();
};
//当value只用到第一个绑定这个参数
const oneValue = computed({
  get() {
    return props.values;
  },
  set(val) {
    emit('update:values', val);
  }
});

// 多选双向绑定
const checkGroupValue = computed({
  get() {
    return props.values;
  },
  set(val) {
    emit('update:values', val);
  }
});

// 储存数组对象的values
// const objArrValues = computed({
//   get() {
//     return props.values;
//   },
//   set(val) {
//     emit('update:values', val);
//   },
// });

// const getDepartmentList = () => {};
</script>

<style></style>
